﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace express.bttree
{
    public class ParamList
    {
        List<object> orignal;
        public ParamList(List<object> orignal)
        {
            if(orignal == null)
            {
                this.orignal = new List<object>();
            } else
            {
                this.orignal = orignal;
            }
        }

        public int ParamCount { 
            get { return orignal.Count; }
        }

        public Object? GetParam(int index)
        {
            if(index >= this.ParamCount)
            {
                return null;
            } 
            else
            {
                return this.orignal[index];
            }
        }

        public int? GetParamAsInt(int index)
        {
            var param = this.GetParam(index);
            if(param == null)
            {
                return null;
            }
            else
            {
                int result;
                var ok = int.TryParse(param.ToString(), out result);
                return ok ? result : null;
            }
        }

        public long? GetParamAsLong(int index)
        {
            var param = this.GetParam(index);
            if (param == null)
            {
                return null;
            }
            else
            {
                long result;
                var ok = long.TryParse(param.ToString(), out result);
                return ok ? result : null;
            }
        }

        public bool? GetParamAsBool(int index)
        {
            var param = this.GetParam(index);
            if (param == null)
            {
                return null;
            }
            else
            {
                bool result;
                var ok = bool.TryParse(param.ToString(), out result);
                return ok ? result : null;
            }
        }

        public double? GetParamAsDouble(int index)
        {
            var param = this.GetParam(index);
            if (param == null)
            {
                return null;
            }
            else
            {
                double result;
                var ok = double.TryParse(param.ToString(), out result);
                return ok ? result : null;
            }
        }

        public float? GetParamAsFloat(int index)
        {
            var param = this.GetParam(index);
            if (param == null)
            {
                return null;
            }
            else
            {
                float result;
                var ok = float.TryParse(param.ToString(), out result);
                return ok ? result : null;
            }
        }

        public string? GetParamAsString(int index)
        {
            var param = this.GetParam(index);
            if (param == null)
            {
                return null;
            }
            else
            {
                return param.ToString();
            }
        }
    }
}
